package com.myy.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class Main {
    public static void main(String[] args) {



    }

    private static void select(String name){
            //注册驱动
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");

            //第2步： 创建数据库链接
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "123456");
            //第三步： 定义SQL语句
            String sql = "INSERT into user(name,age,password)  VALUES('小明')";


        } catch (ClassNotFoundException | SQLException e) {
            throw new RuntimeException(e);
        }
    }

    private static  void insert(){
        //第1步： 导入Mysql的驱动
        try {
            //注册驱动
            Class.forName("com.mysql.cj.jdbc.Driver");
            //第2步： 创建数据库链接
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "123456");
            //第三步： 定义SQL语句
            String sql = "INSERT into user(name,age,password)  VALUES('小明',18,'123456')";
            Statement stmt = conn.createStatement();
            int count = stmt.executeUpdate(sql);
            System.out.println(count);
            stmt.close();
            conn.close();
        } catch (ClassNotFoundException | SQLException e) {
            throw new RuntimeException(e);
        }
    }
}